From 6535276c3e59461eb712a2c283e2b6b7367f3129 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 30 Apr 2015 01:21:26 -0400 Subject: [PATCH] GtkBuilder: Emit a more detailed error for templates Add the class and parent class name to the error message. gtk-builder-tool will parse the error message and use the class names for trying again to parse the file as a template. --- gtk/gtkbuilderparser.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c index 998357de48..160c7bcdb5 100644 --- a/gtk/gtkbuilderparser.c +++ b/gtk/gtkbuilderparser.c @@ -420,23 +420,28 @@ parse_template (GMarkupParseContext *context, template_type = _gtk_builder_get_template_type (data->builder); - if (template_type == 0) + if (!g_markup_collect_attributes (element_name, names, values, error, + G_MARKUP_COLLECT_STRING, "class", &object_class, + G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "parent", &parent_class, + G_MARKUP_COLLECT_INVALID)) { - error_unhandled_tag (data, "template", error); + _gtk_builder_prefix_error (data->builder, data->ctx, error); return; } - else if (state_peek (data) != NULL) + + if (template_type == 0) { - error_invalid_tag (data, "template", NULL, error); + g_set_error (error, + GTK_BUILDER_ERROR, + GTK_BUILDER_ERROR_UNHANDLED_TAG, + "Not expecting to handle a template (class '%s', parent '%s')", + object_class, parent_class ? parent_class : "GtkWidget"); + _gtk_builder_prefix_error (data->builder, context, error); return; } - - if (!g_markup_collect_attributes (element_name, names, values, error, - G_MARKUP_COLLECT_STRING, "class", &object_class, - G_MARKUP_COLLECT_STRING|G_MARKUP_COLLECT_OPTIONAL, "parent", &parent_class, - G_MARKUP_COLLECT_INVALID)) + else if (state_peek (data) != NULL) { - _gtk_builder_prefix_error (data->builder, data->ctx, error); + error_invalid_tag (data, "template", NULL, error); return; } -- 2.30.2